import { useState, useEffect } from "react"
import { ConfigProvider, theme } from "antd"
import zh_CN from "antd/lib/locale/zh_CN"

// 导入路由组件
import RouterComponent from "./routes/RouterComponent"

// 样式导入
import "./styles/global.less"

// Mock数据
import "./mock"

const App = () => {
  const [isLoggedIn, setIsLoggedIn] = useState(false)

  useEffect(() => {
    // 检查本地存储中是否有token
    const token = localStorage.getItem("token")
    if (token) {
      setIsLoggedIn(true)
    }
  }, [])

  // 登录处理函数
  const handleLogin = (token) => {
    localStorage.setItem("token", token)
    setIsLoggedIn(true)
  }

  // 登出处理函数
  const handleLogout = () => {
    localStorage.removeItem("token")
    setIsLoggedIn(false)
  }

  return (
    <ConfigProvider
      locale={zh_CN}
      theme={{
        algorithm: theme.defaultAlgorithm,
        token: {
          colorPrimary: "#C13584", // 主题色为婚礼粉色调
          borderRadius: 4,
        },
      }}
    >
      <RouterComponent
        isLoggedIn={isLoggedIn}
        handleLogin={handleLogin}
        handleLogout={handleLogout}
      />
    </ConfigProvider>
  )
}

export default App
